/*
 * @lc app=leetcode.cn id=1816 lang=typescript
 *
 * [1816] 截断句子
 */

// @lc code=start
function truncateSentence(s: string, k: number): string {
    let count = 0;
    let result = "";
    for (let i = 0; i < s.length; i++) {
        const element = s[i];
        if (element === " ") {
            count++;
            if (count === k) break;
        }
        result += element;
    }
    return result;
}
// @lc code=end
